package com.jm.springboot21.mapper;

import com.jm.springboot21.pojo.Expr;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExprMapper {
    @Insert("INSERT INTO emp_expr(emp_id, begin, end, company, job) " +
            "VALUES(#{empId}, #{begin}, #{end}, #{company}, #{job})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Expr expr);

    @Update("UPDATE emp_expr SET begin=#{begin}, end=#{end}, " +
            "company=#{company}, job=#{job} WHERE id=#{id}")
    int update(Expr expr);

    @Delete("DELETE FROM emp_expr WHERE id=#{id}")
    int delete(Integer id);

    @Select("SELECT * FROM emp_expr WHERE emp_id=#{empId}")
    List<Expr> findByEmpId(Integer empId);

    @Select("SELECT * FROM emp_expr WHERE id=#{id}")
    Expr findById(Integer id);
    //添加多条数据
    @Insert("<script>" +
            "INSERT INTO emp_expr(emp_id, begin, end, company, job) " +
            "VALUES " +
            "<foreach collection='exprs' item='expr' separator=','>" +
            "(#{expr.empId}, #{expr.begin}, #{expr.end}, #{expr.company}, #{expr.job})" +
            "</foreach>" +
            "</script>")
    void addExprs(List<Expr> exprs);
}
